package com.qf.android.huihui.adapter.shopping;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.qf.android.huihui.R;
import com.qf.android.huihui.bean.show.shoppingbottom.Hot;
import com.qf.android.huihui.common.IClickListern;

import java.util.List;

/**
 * Created by 韩爽 on 2017/1/12.
 */

public class ShoppingHotAdapter extends ShoppingBaseAdapter{
    private List<Hot.DataBean.ListBean> list;
    private Context context;
    public ShoppingHotAdapter(List<Hot.DataBean.ListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View  view= LayoutInflater.from(context).inflate(R.layout.fragment_shopping_hot_item,parent,false);
        MyHolder myHolder=new MyHolder(view,listern);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        Hot.DataBean.ListBean listBean = list.get(position);
        MyHolder holder1 = (MyHolder) holder;
        Glide.with(context).load(listBean.getImageUrl()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder1.imageView);
        holder1.title.setText(listBean.getTitle());
        holder1.price_1.setText(listBean.getPrice());
        holder1.price_2.setText(listBean.getSubPrice());
        holder1.itemView.setTag(listBean.getUrl());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void setMyClickListener(IClickListern listener) {
       this.listern=listener;
    }

    public class MyHolder extends ShoppingBaseAdapter.MyHolder {
        private ImageView imageView;
        private TextView title;
        private TextView price_1;
        private TextView price_2;
        private IClickListern listern;
        public MyHolder(View itemView, IClickListern listern) {
            super(itemView, listern);
            this.listern=listern;
            imageView= (ImageView) itemView.findViewById(R.id.hot_item_imageview);
            title= (TextView) itemView.findViewById(R.id.hot_item_title);
            price_1= (TextView) itemView.findViewById(R.id.hot_item_price_1);
            price_2= (TextView) itemView.findViewById(R.id.hot_item_price_2);
        }

        @Override
        public void onClick(View v) {
           if(listern!=null){
               listern.OnItemClick(v,(String)v.getTag());
            }
        }
    }
}
